$(function() {
	var CLASS_ACTIVE = 'mui-active';
	var RE_MOBILE = /^1\d{10}$/;
	/**
	 * 消息提示=》使用jquery重写 mui.toast
	 * @param {Object} message==>消息
	 * @param {Object} options==>配置
	 */
	$.toast = function(message, options) {
		var durations = {
			'long': 3500,
			'short': 2000
		};

		//计算显示时间
		options = $.extend({
			duration: 'short'
		}, options || {});

		if(typeof options.duration === 'number') {
			duration = options.duration > 0 ? options.duration : durations['short'];
		} else {
			duration = durations[options.duration];
		}
		if(!duration) {
			duration = durations['short'];
		}
		var toast = document.createElement('div');
		toast.classList.add('mui-toast-container');
		toast.innerHTML = '<div class="' + 'mui-toast-message' + '">' + message + '</div>';
		toast.addEventListener('webkitTransitionEnd', function() {
			if(!toast.classList.contains(CLASS_ACTIVE)) {
				toast.parentNode.removeChild(toast);
				toast = null;
			}
		});
		//点击则自动消失
		toast.addEventListener('click', function() {
			toast.parentNode.removeChild(toast);
			toast = null;
		});
		document.body.appendChild(toast);
		toast.offsetHeight;
		toast.classList.add(CLASS_ACTIVE);
		setTimeout(function() {
			toast && toast.classList.remove(CLASS_ACTIVE);
		}, duration);

		return {
			isVisible: function() {
				return !!toast;
			}
		}

	};
	
	/**
	 * 登录
	 * @param {Object} mobile==>手机号码
	 * @param {Object} password==>密码
	 * @param {Object} callback==>回调函数
	 */
	$.login = function(mobile, password,callback) {
		var MOBILE_CODE = 1;
		var PASSWORD_CODE = 2;
		var SUCCESS_CODE = 99;
		//手机号码是否存在
		if(mobile === undefined) {
			$.toast("请填写手机号");
			return MOBILE_CODE;
		}
		//手机号码是否正确
		if(!RE_MOBILE.test(mobile)) {
			$.toast("手机号码不正确");
			return MOBILE_CODE;
		}
		if(password === undefined ||
			password.trim().length === 0) {
			$.toast("请输入密码");
			return PASSWORD_CODE;
		}
		$.toast("登录成功");
		return SUCCESS_CODE;
	}
	
	/**
	 * 注册
	 * @param {Object} mobile==>手机号码
	 * @param {Object} password==>密码
	 * @param {Object} callback==>回调函数
	 */
	$.reg = function(mobile, password,repass,callback) {
		var MOBILE_CODE = 1;
		var PASSWORD_CODE = 2;
		var REPASSWORD_CODE = 3;
		var SUCCESS_CODE = 99;
		//手机号码是否存在
		if(mobile === undefined) {
			$.toast("请填写手机号");
			return MOBILE_CODE;
		}
		//手机号码是否正确
		if(!RE_MOBILE.test(mobile)) {
			$.toast("手机号码不正确");
			return MOBILE_CODE;
		}
		//密码验证
		if(password === undefined ||
			password.trim().length === 0) {
			$.toast("请输入密码");
			return PASSWORD_CODE;
		}
		//确认密码
		if(repass === undefined ||
			repass.trim().length === 0) {
			$.toast("请输入确认密码");
			return REPASSWORD_CODE;
		}
		console.dir(password+"<==>"+repass);
		//确认密码
		if(password !== repass) {
			$.toast("两次密码输入不一致");
			return PASSWORD_CODE;
		}
		$.toast("注册成功");
		return SUCCESS_CODE;
	}
})